import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Main {

    public static void main(String[] args) {
        int[] arr = {6, 3, 5, 4, 1, 9, 8, 7};
        int[] arr2 = {1, 2, 3, 4, 5, 6, 7, 8, 9};
        Main main = new Main();
//        main.selectionSort(arr);
//        main.bubbleSort(arr);
//        main.selectionSort(arr);

        System.out.println(0 ^ 2323);
    }

    public void bubbleSort(int[] arrs) {

        int length = arrs.length;

        int count = 0;

        for (int i = 0; i < length; i++) {

            boolean flag = false;

            // 因为最后一个索引后面没有值进行交换，所以要-1
            for (int j = 0; j < length - i - 1; j++) {
                if (arrs[j] > arrs[j + 1]) {
                    int temp = arrs[j + 1];
                    arrs[j + 1] = arrs[j];
                    arrs[j] = temp;
                    flag = true;
                }
                count++;
            }
            if (!flag) {
                break;
            }
        }
        System.out.println(Arrays.toString(arrs));
        System.out.println("count: " + count);

    }

    public void selectionSort(int[] arrs) {

        int length = arrs.length;

        for (int i = 0; i < length - 1; i++) {

            // 定义最小值的索引，默认为未排序第一个
            int minIndex = i;

            for (int j = i + 1; j < length; j++) {
                // 比较找出最小值
                if (arrs[j] < arrs[minIndex]) {
                    minIndex = j;
                }
            }
            // 交换
            int temp = arrs[minIndex];
            arrs[minIndex] = arrs[i];
            arrs[i] = temp;
        }

        System.out.print(Arrays.toString(arrs));
    }

    public void insertSort(int[] arrs) {

        int length = arrs.length;

        for (int i = 1; i < length; i++) {

            int preIndex = i - 1;
            int current = arrs[i];

            while (preIndex >= 0 && current < arrs[preIndex]) {
                arrs[preIndex + 1] = arrs[preIndex];
                preIndex--;
            }
            arrs[preIndex + 1] = current;
        }
        System.out.print(Arrays.toString(arrs));
    }
}